;(function($){
	$.guest_order = $.guest_order || {}
	$.fn.guest_order = function(opts){
		var el = this;
		var opt = {
			th:"",
			ct_brzd:{},
			operBtnDivId:"",
			dataBack : function(){},
			closeBack : function(){},
		}
		var param = $.extend(opt,opts);
		var app = new App(el,param);
		$.guest_order = $.extend($.guest_order,app);
	}
	
	var App = function(el,param){
		this.el = el;
		this.param = param;
		this.initHtml();
		this.bindEvent();
	}
	
	App.prototype = {
		bindEvent : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			$(".accountCode").unbind("click").click(function(){
				$(".accountCode").toggle();
				var type = $(this).data("type");
//	 			console.log(type)
				$("#goodsMenu").find(".pd_info").empty();
				if(type=="code"){
					$("#goodsCb").css({"height":"136"});
					setSize();
					$.spa_front_account_type.initCodeHtml();
				}else if(type=="type"){
					$("#goodsCb").css({"height":"110"});
					$("#nav-search").remove();
					setSize();
					$.spa_front_account_menu.param.pym = "";
					$.spa_front_account_type.initGoodsCbHtml();
				}
			})
			
			//入账商品
			$("#goodsMenu").spa_front_account_menu({
				wait : wait,
				goon : goon,
				bmh : $.HSAPI_HEADERS.bmh,
				th : param.th,
				ct_brzd:param.ct_brzd,
				width : $("#pageRight").width(),
				height : $("#goodsMenu").find(".pd_info").height(),
				dataBack : function(){
					param.dataBack();
				},
				closeBack : function(){},
			})
			
			//入账商品大类
			$("#goodsCb").spa_front_account_type({
				ds : [],
				wait : wait,
				goon : goon,
				bmh : $.HSAPI_HEADERS.bmh,
				clickBack : function(ds){
					$.spa_front_account_menu.param.page = 1;
					$.spa_front_account_menu.param.cb_bh = ds.bh
					$.spa_front_account_menu.initDs();
				},
				pymBack : function(pym){
					$.spa_front_account_menu.param.page = 1;
					$.spa_front_account_menu.param.pym = pym;
					$.spa_front_account_menu.initDs();
				},
				dataBack : function(jdh){
				},
				closeBack : function(){
				}
			});
		},
		initHtml : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			$.ajaxSetup({async: false,cache: false});
            $.getScript("js/cashier_mana/jquery.service.spa_front_account_type.js");
            $.getScript("js/cashier_mana/jquery.service.spa_front_account_menu.js");
            $.getScript("assets/js/fuelux/fuelux.spinner.js");
            $.getScript("assets/js/ace/elements.spinner.js");
            $.ajaxSetup({async: true});
            
            
            var csstext = 	'<style>'+
								'button.dishes_type_each{margin:1px !important;}'+
								'.goodsCb .btn.btn-app{line-height: 22px;font-size: 20px;display: inline-block;font-weight: normal;border: none;border-radius: 6px;border-top-left-radius: 6px;border-top-right-radius: 6px;border-bottom-right-radius: 6px;border-bottom-left-radius: 6px;padding: 12px 0 8px;margin: 1px;position: relative;}'+
								'.pd_info > a.btn.btn-app:focus,td .btn.btn-app:focus{border : 2px solid #d15b47 !important;background : #2b8ccc !important;color : white !important;}'+
							'</style>';
			$(csstext).appendTo(el)
			
			$("#"+param.operBtnDivId).find(".oper_btn1").remove();
			var btnHtml = 	'';
			$("#"+param.operBtnDivId).append(btnHtml)
			
			el.find("#guestOrder").remove()
			var html = 	'<div id="guestOrder">'+
							'<div id="menuContainer">'+
									'<div id="goodsCb" class="widget-box goodsCb" style="height:110px;">'+
								'</div>'+
								'<div id="goodsMenu" class="widget-box no-margin" style="" >'+
									'<div class="pd_info" style=""></div>'+
								'</div>'+
							'</div>'+
							'<div class="widget-box no-margin" style="height:73px;border-top:0px;padding: 6px;">'+
								'<button type="button" class="btn btn-app btn-sm btn-light accountCode" data-type="code" style="height:58px;">'+
									'<span data-i18n="助记码" class="blue">助记码</span>'+
								'</button>'+
								'<button type="button" class="btn btn-app btn-sm btn-light accountCode" data-type="type" style="height:58px;display:none;">'+
									'<span data-i18n="分类" class="blue">分类</span>'+
								'</button>'+
							'</div>'+
						'</div>';
			el.append(html)
			
			el.find(".pd_info").css("height",$(window).height()-100-73-18-43-2-60)
		},
		
	}
	
	function setSize(){
		var winh = $(window).height();
		var top = $("#menuContainer").offset().top;
		var h = winh - top - 69-5;
		$("#menuContainer").css({"height":h});
		
		var top1 = $("#goodsMenu").find(".pd_info").offset().top;
		var hh = h - (top1 - top)-60;
		$("#goodsMenu").find(".pd_info").css("height",hh)
		
	}
})(jQuery);